package com.fs.common;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

public class UploadUtils {
    //定义一个常量 用来记录文件存放的路径
    public static final String RESOURCE="D:/Suke/";
    public static void createDirectory(String path){
        File file=new File(path);
        if(!file.exists()){
            file.mkdirs();//创建指定目录
        }
    }
    public static String uploadVideo(String userId, MultipartFile file) {
        String path=UploadUtils.RESOURCE+userId+"/video/";
        String pathDB="/"+userId+"/video/";
        createDirectory(path);
        //获取文件名
        String filename = file.getOriginalFilename();
        pathDB=pathDB+filename;
        File filePath=new File(path+filename);
        try {
            file.transferTo(filePath);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return pathDB;
    }
}